<template>
  <div class="config-view">
    <div v-if="showConfigTable">
      <div class="config-view-button">
        <el-button type="primary" @click="addTemplateConfig()">新增模板</el-button>
      </div>
      <el-table :data="state.configTableData" border style="width: 100%">
        <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
        <el-table-column prop="name" label="模板名称" align="center"></el-table-column>
        <el-table-column fixed="right" label="操作" width="100" align="center">
          <template #default="scope">
            <el-button @click="editClick(scope.row)" type="primary" plain size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 1.选大学弹窗 -->
    <el-dialog
      width="35%"
      title="学校列表"
      :close-on-click-modal="false"
      @close="closeDialog"
      v-model="innerVisible"
      append-to-body>
      <div class="add-major-school" id="content">
        <el-input :disabled='schoolSearchDisable' @keyup.enter="searchSchool" v-model="schoolSearchName" clearable placeholder="请输入要搜索的学校名称" class="input-with-select">
          <template #prepend>
            <el-select :disabled='schoolSearchDisable' v-model="pageInfo.extra" @change="changeExtra" style="width: 100px;padding: 0;" multiple placeholder="类型选择">
              <el-option label="985" :value="985"></el-option>
              <el-option label="211" :value="211"></el-option>
              <el-option label="双非" value="n92"></el-option>
            </el-select>
          </template>
          <template #append>
            <el-button :disabled='schoolSearchDisable' class="input-with-button" @click="searchSchool">搜索</el-button>
          </template>
        </el-input>
        <div style="margin-top:5px;display: flex;align-items: center;" v-if="(schoolSearchName === 'n92' || isShowPage) && !schoolSearchDisable">
          <el-radio-group v-model="pageInfo.limit">
            <el-radio-button label="20" :value="20"></el-radio-button>
            <el-radio-button label="40" :value="40" ></el-radio-button>
            <el-radio-button label="60" :value="60"></el-radio-button>
            <el-radio-button label="80" :value="80"></el-radio-button>
            <el-radio-button label="100" :value="100"></el-radio-button>
            <el-radio-button label="200" :value="200"></el-radio-button>
          </el-radio-group>
          <span style="margin-left:5px">条</span>
        </div>
        <div v-if="state.optionsCollegesList.length < 1" class="add-major-title">
          <p class="major-title1">系统支持以下搜索模式：</p>
          <p>1、根据大学类型进行搜索，比如点击顶部<span class="major-title2">“类型选择”</span>下拉框的<span class="major-title2">“985”</span>，可以搜索出“北京大学”等985大学；点击<span class="major-title2">“211”</span>，可以搜索出“北京理工大学”等211大学；点击<span class="major-title2">“双非”</span>，可以搜索出“三亚学院”、“三亚大学”等“双非”大学（因“双非”学校数量大，为方便您筛选，系统对“双非”学校进行分页展示，每页可展示20/40/60/80/100/200所学校）。</p>
          <p>2、根据中文名称模糊搜索，比如输入<span class="major-title2">“科技”</span>两个字，可以搜索出“安徽科技学院”、“北京电子科技学院”等包含“科技”两个字的大学（如果选择了某个大学类型，比如985，则搜索出包含“科技”两个字的985大学）。</p>
          <p>3、根据拼音缩写字母进行搜索，比如输入<span class="major-title2">“sc”</span>两个字母，可以搜索出“四川外国语大学成都学院”、“四川农业大学”等以“sc”名称拼音缩写开头的大学（如果选择了某个大学类型，比如985，则搜索出以“sc”名称拼音缩写开头的985大学）。</p>
        </div>
        <div v-if="state.optionsCollegesList.length > 0">
          <div style="font-size:13px;margin-top:5px;color:rgb(230, 162, 60)">如果要搜索其他学校,请取消已选中的学校再进行搜索哦</div>
          <div>
            <div class="add-major-gpa" v-if="isSreach">
              <el-input-number :min="0" v-model="defaultValue" :placeholder="'请输入默认' + typeName"></el-input-number>
              <el-button type="primary" @click="makeSureSchoolGPA()">确定</el-button>
              <span class="major-gpa-title">点·确定·批量设置{{typeName}}</span>
            </div>
            <div class="add-major-allcheckbox">
              <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
              <div>共{{state.optionsCollegesList.length}}条</div>
            </div>
          </div>
          <el-checkbox-group class="checkbox-view" v-model="state.collegesListDate" @change="changeSelectCollegesList">
            <div v-for="item in state.optionsCollegesList" :key="item.id">
              <el-checkbox :disabled="item.isDisabled" :label="item.name" :value="item.id"></el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
      </div>
    </el-dialog>
    <!-- 2.已选中的大学 -->
    <div v-if="!showConfigTable">
      <div class="add-major-button">
        <div>
          <el-button type="primary" plain @click="chooseSchool">点击选择国内大学</el-button>
          <el-button type="warning" @click="batchImport">批量导入</el-button>
        </div>
        <el-button v-if="state.collegesListDate.length > 0" type="danger" plain @click="batchDeletion">批量删除</el-button>
      </div>
      <el-table :data="state.collegesTableData" v-loading="loadingTable" element-loading-text="加载中请稍后..." height="250" @selection-change="handleSelectionChange" border style="width: 100%">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" align="center" width="60" label="序号"></el-table-column>
        <el-table-column prop="name" align="center" label="学校名称"> </el-table-column>
        <el-table-column prop="" align="center" :label="typeName" width="140">
          <template #default="scope">
            <el-input-number style="width: 100%;" v-model="scope.row.GPA"  :min="0" :label="'输入'+ typeName" ></el-input-number>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="100">
          <template #default="scope">
            <el-button type="danger" style="width: 50px;height: 25px;" plain @click="deleteSchoolRow(scope.$index,state.collegesTableData)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-input class="add-major-input" placeholder="请输入模板名称" v-model="templateName" clearable> </el-input>
      <div class="add-major-bottom">
        <el-button @click="onsubmitConfig(0)">取消</el-button>
        <el-button type="primary" @click="onsubmitConfig(1)">确定</el-button>
      </div>
    </div>
    <!--3.批量导入  -->
    <el-dialog
      width="20%"
      title="请选择Excel文件导入大学数据"
      :close-on-click-modal="false"
      v-model="batchCollegesVisible">
      <div v-if="batchCollegesVisible" v-loading="batchloading" element-loading-text="正在导入,请稍等..." style="margin-top: 15px;">
        <div class="view-main-table-upload">
          <input type="file" @change="handleFileChange" accept=".xlsx, .xls">
        </div>
        <el-button type="primary" @click="uploadFile">提交</el-button>
      </div>
    </el-dialog>
    <!-- 错误数据提示 -->
    <el-dialog
      width="390"
      style="text-align: start;"
      title="提示"
      :close-on-click-modal="false"
      v-model="errorMessageVisible">
      <div v-if="errorMessageVisible" style="line-height: 23px;">
        <div>您有<span style="color: red;font-weight: 600;"> {{failList.length}} </span>条数据(见下表)导入失败,请确认大学名称或GPA分数填写是否正确:</div>
        <div v-for="(item,index) of failList" :key="index">
          <div style="margin-left: 100px;color: red;">{{item}}</div>
        </div>
      </div>
      <div style="text-align: end;margin-top: 15px;"><el-button type="primary" @click="errorMessageVisible = false">确 定</el-button></div>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref,reactive,onMounted ,h} from 'vue';
import { ElMessage ,ElMessageBox} from 'element-plus';
import API from "@/utils/api";
import { defineProps, defineEmits } from 'vue';
import { serverUrl } from '@/utils/const'
import axios from 'axios';
import router from "@/router/index";
const props = defineProps({
  parmas: Object,
});
const emits = defineEmits(['closeConfig']);
let typeStatus = ref(null)
let templateName = ref('')
let showConfigTable = ref(true)
let typeName = ref('GPA')
let defaultValue = ref()
let loading = ref(false)
let innerVisible = ref(false)
let isSreach = ref(false)
let schoolSearchName = ref()
let schoolSearchDisable = ref(false)
let isIndeterminate = ref(true)
let checkAll = ref(false)
let loadingTable = ref(false)
let isShowPage = ref(false)
let pageInfo = reactive({
  limit:null,
  currentPage:1,
  pageTotal:0,
  totalNumber:null,
  extra:[],
})
let state = reactive({
  configTableData:[],
  optionsCollegesList:[],
  collegesTableData:[],
  collegesListDate:[],
  cloneCollegesList:[],
  selectSchoolList:[],  //选中的学校数据
  optionsCollegesList_:[],   //搜索出来的数据
  list1:[],
  allList:[],
  handleSelectList:[],    //选中批量删除的数据
  itemInfo:{},
});
let batchCollegesVisible = ref(false)
let selectedFile = ref(null)
const batchImport = (() => {
  batchCollegesVisible.value = true
})
const handleFileChange = (event) => {
  selectedFile.value = event.target.files[0];
};
let batchloading = ref(false)
let errorMessageVisible = ref(false)
let failList = ref([])
async function uploadFile() {
  if(!selectedFile.value) {
    return ElMessage.warning('请选择要上传的excel文件')
  }
  const formData = new FormData();
  formData.append('file', selectedFile.value);
  batchloading.value = true
  try {
    const response = await axios.post(serverUrl+'/admin/degree/upload-gpa', formData, {
      headers: {
        'Content-Type': 'multipart/form-data',
        'token-admin': localStorage.getItem('token'),
      }
    });
    if(response.data.code === 0) {
      batchloading.value = false
      if(response.data.data.success.length > 0) {
        ElMessage.success(response.data.data.success.length + '条数据导入成功')
      }
      batchCollegesVisible.value = false
      state.collegesListDate = []
      state.collegesTableData = response.data.data.success
      response.data.data.success.forEach((item,index) => {
        state.collegesListDate.push(item.id)
      })
      state.selectSchoolList = state.collegesTableData
      if(response.data.data.fail.length > 0) {
        errorMessageVisible.value = true
        failList.value = response.data.data.fail
        // let messageInfo = response.data.data.fail.join(',')
        // ElMessageBox({
        //   confirmButtonText: '确定',
        //   title: '提示',
        //   message: h('p', null, [
        //     h('span', null, '您有'),
        //     h('i', { style: 'color: red' }, `${response.data.data.fail.length}`),
        //     h('span', null, '条数据导入失败,失败数据:'),
        //     h('i', { style: 'color: red' }, `${messageInfo}`),
        //   ]),
        //   showCancelButton:false,
        //   type: 'warning',
        // }).then(() => {}).catch(() => {});
      }
    }
    if(response.data.code === 401) {
      ElMessage.warning('未登录')
      localStorage.removeItem('token')
      localStorage.removeItem('operationStatus')
      router.push({path: '/'})
    }
  } catch (error) {
    batchloading.value = false
  }
}
// 新增大学模板
function addTemplateConfig(val) {
  showConfigTable.value = false
  // innerVisible.value = true
  typeStatus.value = null
}
// 编辑大学模板
function editClick(val) {
  state.itemInfo = val
  typeStatus.value = 'update'
  templateName.value = val.name
  showConfigTable.value = false
  getConfigTemplateColleges(val.id)
}
// 模板(取消)确定提交
function onsubmitConfig(val) {
  if(val === 1) {   //确定
    if(state.collegesTableData.length === 0) {
      return ElMessage.warning('请选择大学')
    }
    if(!templateName.value) {
      return ElMessage.warning('请输入模板名称')
    }
    // 1.国内学校数据处理
    state.collegesTableData.forEach(item => {
      delete item.name
    })
    if(typeStatus.value == 'update') {   //修改
      API.schoolList.updateTemplateData({id:state.itemInfo.id,name:templateName.value,colleges_id:state.itemInfo.colleges_id,gpas:state.collegesTableData}, (res) => {
        if(res.code === 0) {
          ElMessage.success('修改成功')
          getTemplateList()
          showConfigTable.value = true
        }
      })
    }else {   //新增
      API.schoolList.addTemplateData({name:templateName.value,colleges_id:props.parmas.itemInfo.id,gpas:state.collegesTableData}, (res) => {
        if(res.code === 0) {
          ElMessage.success('新增成功')
          getTemplateList()
          showConfigTable.value = true
        }
      })
    }
  }else {    //取消
    showConfigTable.value = true
    state.collegesTableData = []
  }
}
// 点击全选按钮
function handleCheckAllChange(val) {
  // console.log(checkAll.value ,'val');
  let list = []
  state.optionsCollegesList.forEach((item) => {
    list.push(item.id)
  })
  if(!val) {
    var newArray = state.collegesListDate.filter(function(item) {
        return list.indexOf(item) === -1;
    });
    state.collegesListDate = newArray
    schoolSearchDisable.value = false
  }else {
    var newArray = list.concat(state.collegesListDate);
    state.collegesListDate = newArray
    schoolSearchDisable.value = true
  }
  state.collegesTableData.forEach((item,index) => {
    if(item.GPA === 0) {
      delete state.collegesTableData[index]
    }
  })
  const tab = state.collegesTableData.filter(item => item !== "" && item !== null && item !== undefined);
  state.collegesTableData = tab
  // console.log(schoolSearchDisable.value,'schoolSearchDisable.value');
  isIndeterminate.value = false
}
// 关闭弹出事件
function closeDialog() {
  checkAll.value = false
  schoolSearchDisable.value = false
  schoolSearchName.value = null
  state.optionsCollegesList = []
  pageInfo.limit = null
  pageInfo.extra = []
  isShowPage.value = false
  state.selectSchoolList.forEach((item,index) => {
    if(item. GPA === 0) {
      delete state.selectSchoolList[index]
    }
  })
  const tab = state.collegesTableData.filter(item => item !== "" && item !== null && item !== undefined);
  const select = state.selectSchoolList.filter(item => item !== "" && item !== null && item !== undefined);
  state.selectSchoolList = select
  state.collegesTableData = tab
  // console.log(state.collegesTableData,'state.collegesTableData');
  // console.log(state.selectSchoolList,'state.selectSchoolList');
}
// 点击选择学校按钮
function chooseSchool() {
  innerVisible.value = !innerVisible.value
  isSreach.value = false
  // getCollegesList ()
}
// 选择类型
function changeExtra(val) {
  if(val.length === 2) {
    delete val[0]
  }
  const list = val.filter(item => item !== "" && item !== null && item !== undefined);
  pageInfo.extra = list
  if (pageInfo.extra.includes('n92')) {
    isShowPage.value = true
  }else {
    isShowPage.value = false
  }
}
// 搜索学校数据
function searchSchool() {
  let schoolType = pageInfo.extra.join(',')
  if(schoolSearchName.value || pageInfo.extra.length > 0) {
    schoolSearchDisable.value = true
  }else {
    schoolSearchDisable.value = false
  }
  if(!schoolSearchName.value && pageInfo.extra.length < 1) {
    return ElMessage.warning('请输入关键字或者选择学校类型进行搜索哦')
  }
  if((schoolSearchName.value === 'n92' || schoolType === 'n92') && !pageInfo.limit) {
    schoolSearchDisable.value = false
    return ElMessage.warning('请选择要搜索的条数哦!')
  }
  loading.value = true
  // if(!defaultValue.value && props.parmas.type != 'update') {
  //   let isShow = false
  //   if(state.selectSchoolList.length > 0) {
  //     state.collegesListDate.forEach((item1) => {
  //       state.optionsCollegesList.forEach(item2 => {
  //         if(item1 === item2.id) {
  //           isShow = true
  //         }
  //       })
  //     })
  //   }
  //   if(isShow) {
  //     loading.value = false
  //     return ElMessage.warning('请设置默认值后再搜索其他学校')
  //   }
  // }
  // console.log(state.collegesListDate,'选中的数据');
  let checkList = []
  // console.log(isSreach.value,'isSreach');
  if(state.collegesTableData.length > 0) {
    state.collegesTableData.forEach(item => {
      checkList.push(item.id)
    })
  }
  let exclude_ids_ =  checkList.join(',')
  isSreach.value = true
  defaultValue.value = null
  if(schoolSearchName.value || pageInfo.extra.length > 0) {
    let index = (schoolSearchName.value === 'n92' || schoolType === 'n92') ?  'getCollegesListPage' : 'getCollegesList'
    let parmas = {} 
    if(schoolSearchName.value === 'n92' || schoolType === 'n92') {
      parmas = {
        page:1,
        limit:pageInfo.limit,
        name:schoolSearchName.value,
        exclude_ids:exclude_ids_,
        extra:schoolType,
      }
    }else {
      parmas = {
        name:schoolSearchName.value,
        exclude_ids:exclude_ids_,
        extra:schoolType,
      }
    }
    API.majorList[index](parmas, (res) => {
      if(res.code == 0) {
        loading.value = false
        if(res.data.length > 0) {
          if(schoolSearchName.value === 'n92' || schoolType === 'n92') {
            schoolSearchDisable.value = true
          }
          res.data.forEach(item => {
            state.collegesListDate.push(item.id)
          })
          checkAll.value = true
          isIndeterminate.value = false
          state.optionsCollegesList_ = res.data
          state.optionsCollegesList = res.data
          state.collegesListDate = Array.from(new Set(state.collegesListDate))
          const currentOptions = state.optionsCollegesList.filter(item => 
            state.collegesListDate.includes(item.id)
          );
          // console.log(currentOptions,'currentOptions');
          currentOptions.forEach(option => {
            const existItem = state.selectSchoolList.find(item => item.id === option.id);
            // console.log(existItem,'existItem');
            if (!existItem) {
              state.selectSchoolList.unshift({
                id: option.id,
                name: option.name,
                GPA:0
              });
            }
          });
        }else {
          state.optionsCollegesList = res.data
          schoolSearchDisable.value = false
          ElMessage.warning('无搜索结果或者结果已在列表中无需重复搜索')
        }
        // console.log(state.collegesListDate,'state.collegesListDate走了');
        // console.log(state.selectSchoolList,'state.selectSchoolList走了');
        // state.selectSchoolList.forEach((item) => {
        //   state.optionsCollegesList.forEach(item1 => {
        //     if(item.id === item1.id) {
        //       if(item.GPA >0) {
        //         isSreach.value = false
        //       }else {
        //         isSreach.value = true
        //         defaultValue.value = null
        //       }
        //     }
        //   })
        // })
      }
      // console.log(isSreach.value,'isSreach.value');
    })
  }else {
    // getCollegesList()
    loading.value = false
    isSreach.value = false
    schoolSearchName.value = null
  }
}
// 确认设置默认GPA值
function makeSureSchoolGPA() {
  if(state.collegesTableData.length > 0) {
    if(state.collegesTableData.length == state.collegesListDate.length) {
      return ElMessage.warning(`请先选择学校后在设置默认的${typeName.value}哦`)
    }
  }else {
    if(state.collegesListDate.length < 1) {
      return ElMessage.warning(`请先选择学校后在设置默认的${typeName.value}哦`)
    }
  }
  if(!defaultValue.value) {
    return ElMessage.warning(`默认的${typeName.value}必须大于0哦`)
  }
  // setTimeout(() => {
  //   loadingView.value = true
  // },5000)
  if(defaultValue.value) {
    loading.value = true
    // console.log(state.selectSchoolList,'数据');
    // console.log(state.collegesListDate,'选中的数据');
    let selectList_ = []
    state.collegesListDate.forEach(item => {
      state.selectSchoolList.forEach((item_,index) => {
        if(item === item_.id) {
          selectList_.push(item_)
        }
      })
    })
    selectList_.forEach(item => {
      if(item.GPA < 1) {
        item.GPA = defaultValue.value
      }
    })
    state.selectSchoolList = selectList_
    // getCollegesList()
    isSreach.value = false
    schoolSearchName.value = null
    schoolSearchDisable.value = false
    schoolSearchDisable.value = false
    const list1 = []
    // console.log(state.collegesListDate,'state.collegesListDate');
    // console.log(state.collegesTableData,'tab');
    state.collegesListDate.forEach(item1 => {
      state.cloneCollegesList.forEach(item3 => {
        if(item1 === item3.id) {
          list1.unshift({
            id: item3.id,
            name: item3.name,
            GPA:0,
          })
        }
      })
    })
    if(list1.length > 0) {
      list1.forEach((item,index) => {
        state.selectSchoolList.forEach(item2 => {
          if(item.id === item2.id && item2.GPA != 0) {
            list1[index].GPA = item2.GPA
          }
        })
      })
    }
    // console.log(list1,'list1');
    const newArray = state.collegesTableData.filter(item => item !== "" && item !== null && item !== undefined);
    // console.log(newArray,'newArray');
    if(newArray.length > 0) {
      newArray.forEach((item,index) => {
        list1.forEach((item1,index1) => {
          if(item.id === item1.id) {
            console.log(1);
            list1[index1].GPA = item.GPA
          }
          if(item1.GPA <= 0) {
            list1[index1].GPA = defaultValue.value
          }
        })
      })
    }else {
      list1.forEach((item,index) => {
        item.GPA = defaultValue.value
      })
    }
    state.collegesTableData = list1
    innerVisible.value = false
    loading.value = false
    // console.log(state.collegesTableData,'表格数据');
    defaultValue.value = null
  }
  schoolSearchDisable.value = false
  pageInfo.limit = null
  pageInfo.extra = []
  isShowPage.value = false
}
// 单条删除
function deleteSchoolRow(index,table) {
  state.collegesListDate = []
  state.collegesTableData.splice(index, 1)
  state.selectSchoolList = state.collegesTableData
  state.collegesTableData.forEach(item => {
    state.collegesListDate.push(item.id)
  })
  const tab = state.collegesTableData.filter(item => item !== "" && item !== null && item !== undefined);
  const select = state.selectSchoolList.filter(item => item !== "" && item !== null && item !== undefined);
  state.selectSchoolList = select
  state.collegesTableData = tab
  // console.log(state.selectSchoolList,'state.selectSchoolList');
  // console.log(state.collegesListDate,'state.collegesListDatet');
  // console.log(state.collegesTableData,'table');
  // console.log(tab,'tab');
}
// 批量删除
function batchDeletion () {
  if(state.handleSelectList.length < 1) {
    return ElMessage.warning('请先勾选要删除的学校哦')
  }else {
    loadingTable.value = true
    state.collegesListDate = []
    state.collegesTableData.forEach((item,index) => {
      state.handleSelectList.forEach((item1) => {
        if(item.id === item1.id) {
          delete state.collegesTableData[index]
        }else {
          state.collegesListDate.push(item.id)
        }
      })
    })
    if(state.collegesTableData.length === state.handleSelectList.length) {
      state.collegesListDate = []
    }
    state.selectSchoolList = state.collegesTableData
    loadingTable.value = false
    // console.log(state.collegesTableData,'state.collegesTableData');
  }
  const tab = state.collegesTableData.filter(item => item !== "" && item !== null && item !== undefined);
  const select = state.selectSchoolList.filter(item => item !== "" && item !== null && item !== undefined);
  state.selectSchoolList = select
  state.collegesTableData = tab
}
// 选择批量数据
function handleSelectionChange (val) {
  state.handleSelectList = val
}
// 选中的学校数据
function changeSelectCollegesList(list) {
  let arr = []
  state.optionsCollegesList.forEach((item) => {
    list.forEach(item1 => {
      if(item.id === item1) {
        arr.push(item1)
      }
    })
  })
  let checkedCount = arr.length
  checkAll.value = checkedCount === state.optionsCollegesList.length
  isIndeterminate.value =  checkedCount > 0 && checkedCount <= state.optionsCollegesList.length
  if(!isIndeterminate.value) {
    schoolSearchDisable.value = false
  }else {
    schoolSearchDisable.value = true
  }

  // console.log(state.optionsCollegesList_,'state.optionsCollegesList_');
  // let Array1 = []
  // state.optionsCollegesList_.forEach((item) => {
  //   Array1.push(item.id)
  // })
  // if(schoolSearchName.value) {
  //   if(!containsAll(list,Array1)) {
  //     isSreach.value = true
  //     defaultStatus.value = null
  //   }else {
  //     isSreach.value = false
  //   }
  // }
}
// 获取国内学校数据
function getCollegesList () {
  loading.value = true
  schoolSearchName.value = null
  return new Promise(function(resolve,reject){  
    API.majorList.getCollegesList({}, (res) => {
      loading.value = false
      if(res.code == 0) {
        if(res.data.length > 0) {
          res.data.forEach(item => {
            item.isDisabled = null
          })
        }
        // state.optionsCollegesList = res.data
        state.cloneCollegesList =res.data
        resolve()
      }
    })
  })
}
// 获取后台模板列表
function getTemplateList () {
  loading.value = true
  API.schoolList.getTemplateData({colleges_id:props.parmas.itemInfo.id}, (res) => {
    loading.value = false
    if(res.code == 0) {
      state.configTableData = res.data
    }
  })
}
// 获取某个模板下的大学数据
function getConfigTemplateColleges(id) {
  loadingTable.value = true
  API.schoolList.getConfigTemplateColleges({templates_id:id}, (res) => {
    if(res.code == 0) {
      state.collegesListDate = []
      state.collegesTableData = []
      res.data.forEach((item,index) => {
        state.collegesListDate.push(item.domestic_colleges_id)
        state.cloneCollegesList.forEach((citem,e) => {
          if(item.domestic_colleges_id === citem.id) {
            state.collegesTableData.push({
              id: item.domestic_colleges_id,
              name: citem.name,
              GPA:item.degrees_GPA
            })
          }
        })
      })
      state.selectSchoolList = state.collegesTableData
      loadingTable.value = false
    }
  })
}
onMounted(async() => {
  // console.log(props.parmas,'parmas');
  getTemplateList()
  await getCollegesList()
})
</script>

<style lang="scss" scoped>
.config-view {
  max-height: 400px;
  overflow: auto;
  .config-view-button {
    text-align: start;
    margin-bottom: 15px;
  }
  .add-major-button {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 5px;
  }
  .add-major-bottom {
    margin-top: 10px;
  }
  .add-major-input {
    margin-top: 15px;
  }
  .view-main-table-upload {
    margin-bottom: 20px;
    text-align: start;
  }
}
.add-major-school {
  .major-school-type {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
  }
  .major-school-loading {
    height: 200px;
  }
  .checkbox-view {
    height: 290px;
    overflow: auto;
  }
  .input-with-button {
    color: #fff;
    background: #409eff;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
  .add-major-title {
    .major-title1 {
      font-weight: 600;
    }
    .major-title2 {
      color: #409eff;
    }
  }
  .add-major-gpa {
    display: flex;
    margin: 10px 10px 10px 0;
    align-items: center;
    .el-input-number {
      width: 100%;
      margin-right: 10px;
    }
    .major-gpa-title {
      font-size: 12px;
      margin-left: 5px;
      color: rgb(230, 162, 60);
    }
  }
  .add-major-allcheckbox {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 30%;
  }
}
</style>